<template>
    <div>
        用户名称:<el-input type="text" placeholder="请输入用户名称" v-model="user.name"></el-input>
        <br>
        用户密码:<el-input type="password" placeholder="请输入用户密码" v-model="user.password"></el-input>
        <br>
        <el-button @click="DoLogin">登录</el-button>
    </div>
</template>

<script>
export default {
    name: 'MyLogin',
    data() {
        return {
            user:{
                name:"",
                password:""
            }
        };
    },
    props: {},

    components: {},

    created() {},

    mounted() {},

    methods: {
        DoLogin(){
            this.axios.post('http://127.0.0.1:8000/login/',this.user)
            .then(res => {
                alert("登陆成功",res)
                localStorage.setItem('username',this.user.name)
                this.$router.push('/home')
            })
            .catch(err => {
                alert('登陆失败',err)
            })
        }
    },
    computed: {},

    watch: {},

    directives: {},

    filters: {}
};
</script>

<style scoped>
* {
    margin: 0;
}
</style>
